package com.yang.Offer;

public class Offer21 {
}
class Offer21Solution {
    public int[] exchange(int[] nums) {
        // 双指针分别从头尾扫描
        // left指针找偶数,right指针找偶数
        // 如果两指针相遇则已经交换完了前后分界点的奇偶数
        int left = 0, right = nums.length - 1;
        while(left < right){
            if(nums[left] % 2 == 1){
                left ++;
            }else if(nums[right] % 2 == 0){
                right --;
            }else{
                int temp = nums[left];
                nums[left] = nums[right];
                nums[right] = temp;
                right --;
                left ++;
            }
        }
        return nums;
    }
}
